import Vue from 'vue'
import VueRouter from 'vue-router'
import Case from "./views/case/Case.vue";

Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    redirect: "/case",
  },
  {
    path: '/home',
    name: '授权登录',
    component: () => import('./views/Home.vue')
  },
  {
    path: "/case/applyActivity/:id",
    name: "发布报名活动",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/applyActivity/ApplyActivity.vue"),
  },
  {
    path: "/case/lottoActivity/:id",
    name: "发布大转盘抽奖",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/lottoActivity/ApplyActivity.vue"),
  },
  {
    path: "/case/groupBuying/:id",
    name: "发布拼团",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/groupBuying/ApplyActivity.vue"),
  },
  {
    path: "/case/envelopesTalk/:id",
    name: "发布红包拓客",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/envelopesTalk/ApplyActivity.vue"),
  },
  {
    path: "/case/scratchablelatex/:id",
    name: "发布九宫格抽奖",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/scratchablelatex/ApplyActivity.vue"),
  },
  {
    path: "/case/solitaireplug/:id",
    name: "发布接龙",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/solitaireplug/ApplyActivity.vue"),
  },
  {
    path: "/case/eventCoupons/:id",
    name: "发布优惠券",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/eventCoupons/ApplyActivity.vue"),
  },
  {
    path: "/case/bargaining/:id",
    name: "发布砍价",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/bargaining/ApplyActivity.vue"),
  },
  {
    path: "/case/helpActivity/:id",
    name: "发布助力",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/helpActivity/ApplyActivity.vue"),
  },
  {
    path: "/case/voteplugin/:id",
    name: "发布投票",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/voteplugin/ApplyActivity.vue"),
  },
  {
    path: "/case/moresolitaire/:id",
    name: "发布多商品团购接龙",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/case/moresolitaire/ApplyActivity.vue"),
  },
  {
    path: "/merchant",
    name: "商户信息",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/Merchant.vue"),
  },
  {
    path: "/customer",
    name: "客户管理",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/customer.vue"),
  },
  {
    path: "/business",
    name: "店铺统计",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/business.vue"),
  },
  {
    path: "/addStaff",
    name: "添加核销员",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/AddStaff.vue"),
  },
 {
    path: "/AddEmployee",
    name: "添加员工",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/AddEmployee.vue"),
  },
  {
    path: "/manage/applyList",
    name: "名单",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/manage/ApplyList.vue"),
  },
  {
    path: "/manage/VotepluginList",
    name: "报名信息",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/manage/VotepluginList.vue"),
  },
  {
    path: "/manage/groupList",
    name: "拼团信息",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/manage/groupList.vue"),
  },
  {
    path: "/vip",
    name: "VIP",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/VIP.vue"), 
  },
  {
    path: "/activeProtocol",
    name: "活动发布协议",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/activeProtocol.vue"), 
  },
  {
    path: "/getMoney",
    name: "我要提现",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/GetMoney.vue"),
  },
  // {
  //   path: "/getMoneyRecord",
  //   name: "提现记录",
  //   component: () =>
  //     import(/* webpackChunkName: "about" */ "./views/my/GetMoneyRecord.vue"),
  // },
  {
    path: "/applyGetMoney",
    name: "申请提现",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/ApplyGetMoney.vue"),
  },
  {
    path: "/verification",
    name: "核销",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/Verification.vue"),
  },
  {
    path: "/welcome",
    name: "loading",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/welcome.vue"),
  },
  {
    path: "/VerificationLotto",
    name: "核销奖品",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/VerificationLotto.vue"),
  },
  {
    path: "/VerificationBuying",
    name: "核销商品",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/VerificationBuying.vue"),
  },
  {
    path: "/staffManage",
    name: "核销员管理",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/StaffManage.vue"),
  },
  {
    path: "/promoter/bePromoter",
    name: "申请成为推广员",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/bePromoter.vue"),
  },
  {
    path: "/promoter/merchant",
    name: "我的商户",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/merchant.vue"),
  },
  {
    path: "/promoter/partner1",
    name: "我的下级",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/partner1.vue"),
  },{
    path: "/promoter/partner2",
    name: "他的下级",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/partner2.vue"),
  },
  {
    path: "/promoter/poster",
    name: "推广海报",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/poster.vue"),
  },
  {
    path: "/promoter/bePromoterSubmit",
    name: "等待审核中",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/bePromoterSubmit.vue"),
  },
  {
    path: "/promoter/bePromoterResult",
    name: "申请结果",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/bePromoterResult.vue"),
  },
  {
    path: "/promoter/order",
    name: "我推广的有效订单数",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/order.vue"),
  },
  {
    path: "/promoter/GetMoney",
    name: "GetMoney",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/GetMoney.vue"),
  },
  {
    path: "/promoter/ApplyGetMoney",
    name: "ApplyGetMoney",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/promoter/ApplyGetMoney.vue"),
  },
  {
    path: "/employeeManage",
    name: "员工管理",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/employeeManage.vue"),
  },
  {
     path: "/staffActivity",
     name: "我的活动",
     component: () =>
       import(/* webpackChunkName: "about" */ "./views/my/staffActivity.vue"),
  },
  {
     path: "/myActivity",
     name: "活动数据",
     component: () =>
       import(/* webpackChunkName: "about" */ "./views/my/myActivity.vue"),
  },
  {
     path: "/FansDetails",
     name: "粉丝详情",
     component: () =>
       import(/* webpackChunkName: "about" */ "./views/fans/FansDetails.vue"),
  },
  {
    path: "/case/show/:id",
    name: "案例模板展示",
    component: () =>
      import(/* webpackChunkName: "show" */ "./views/case/Show.vue"),
  },
  {
    path: "/models",
    name: "案例展示",
    component: () =>
      import(/* webpackChunkName: "show" */ "./views/system/models.vue"),
  },
  {
    path: "/case/article/:id",
    name: "文章详情",
    component: () =>
      import(/* webpackChunkName: "article" */ "./views/case/Article.vue"),
  },
  {
    path: "/fans/activityFans/:id",
    name: "当前活动粉丝数据",
    component: () =>
      import(/* webpackChunkName: "article" */ "./views/fans/ActivityFans.vue"),
  },
  {
    path: "/fans/virtual/:id",
    name: "虚拟活动数据",
    component: () =>
      import(/* webpackChunkName: "article" */ "./views/fans/virtual.vue"),
  },
  {
    path: "/promoter",
    name: "推广员",
    component: () =>
      import(/* webpackChunkName: "article" */ "./views/promoter/index.vue"),
  },
  {
    path: "/wrapper",
    component: () =>
      import(/* webpackChunkName: "about" */ "./components/Wrapper"),
    children: [{
        path: "/case",
        name: "Case",
        component: Case,
        meta: { isShowTabbar: true }
      }, {
        path: "/manage",
        name: "Manage",
        component: () =>
        import(/* webpackChunkName: "manage" */ "./views/manage/Manage.vue"),
        meta: { isShowTabbar: true }
      },  {
        path: "/system",
        name: "System ",
        component: () =>
          import(/* webpackChunkName: "fans" */ "./views/system/system.vue"),
        meta: { isShowTabbar: true }
      },{
        path: "/fans",
        name: "Fans",
        component: () =>
          import(/* webpackChunkName: "fans" */ "./views/fans/Fans.vue"),
        meta: { isShowTabbar: true }
      }, {
        path: "/my",
        name: "My",
        component: () =>
          import(/* webpackChunkName: "my" */ "./views/my/My.vue"),
        meta: { isShowTabbar: true }
      }
    ],
  },
];

const router = new VueRouter({
  routes
})

const baseurl = "//xxx"
// 解析url参数并获取code
function getUrlParam(name) {   //name为要获取的参数名
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var rrr = decodeURIComponent(window.location.search);
  var r = rrr.substr(1).match(reg);
  if(r != null) return unescape(r[2]);
  return null; 
}
// 请求微信服务器获取code 方法
function getUserCode() {
  redirectURL = encodeURI((baseurl + window.location.pathname + window.location.search).split('&code')[0]);//获取地址
  const base = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=';
  let state;
  let surl;
  let reserveUrl;
  let appid = "";
  let scope = "1";
  window.location.href =base + appid +'&redirect_uri='+ redirectURL +'&response_type=code&scope='+ scope +  '#wechat_redirect';
}
// 路由守卫
router.beforeEach((to,from,next)=>{
  if(!to.meta.isShowTabbar) {
    document.title = to.name;
  }
  next();
  // if(to.matched.some(res=>res.meta.isLogin)){//判断是否需要登录
  //     if (sessionStorage['username']) {
  //         next();
  //     }else{
  //         next({
  //             path:"/login",
  //             query:{
  //                 redirect:to.fullPath
  //             }
  //         });
  //     }

  // }else{
  //     next()
  // }
});
export default router
